// history.js
Page({
    data: {
      word:'wrod',
      wordop:[
        {text:'历史浏览',value:'wrod'}
      ],
      segmentOptions: [
        { text: '景点', value: 'scenic' },
        { text: '美食', value: 'food' }
      ],
      activeTab: 'scenic', // 默认显示景点
      scenicHistoryList: [], // 景点历史列表
      foodHistoryList: [], // 美食历史列表
      loading: false
    },
  
    // 切换标签
    onChangeSegment(event) {
      this.setData({
        activeTab: event.detail,
      });
      this.loadHistory(); // 切换时加载对应的历史记录
    },
  
    // 加载历史记录
    loadHistory() {
      if (this.data.activeTab === 'scenic') {
        this.setData({
          historyList: this.data.scenicHistoryList,
        });
      } else {
        this.setData({
          historyList: this.data.foodHistoryList,
        });
      }
    },
  
    // 清除历史纪录
    // clear() {
    //   this.setData({ loading: true });
  
    //   setTimeout(() => {
    //     if (this.data.activeTab === 'scenic') {
    //       wx.removeStorageSync('scenicHistory');
    //       this.setData({
    //         scenicHistoryList: [],
    //         loading: false,
    //       });
    //       wx.showToast({
    //         title: '景点历史清除成功',
    //         icon: 'success',
    //         duration: 2000,
    //       });
    //     } else {
    //       wx.removeStorageSync('foodHistory');
    //       this.setData({
    //         foodHistoryList: [],
    //         loading: false,
    //       });
    //       wx.showToast({
    //         title: '美食历史清除成功',
    //         icon: 'success',
    //         duration: 2000,
    //       });
    //     }
    //   }, 1000);
    // },
  
    // 跳转到详情页面
    navigateToDetail(event) {
      const id = event.currentTarget.dataset.id;
      if (this.data.activeTab === 'scenic') {
        wx.navigateTo({
          url: `/pages/scenicIntroduction/scenicIntroduction?id=${id}`,
        });
      } else {
        wx.navigateTo({
          url: `/pages/foodDetail/foodDetail?id=${id}`,
        });
      }
    },
  
    // 页面加载时读取历史记录
    onLoad() {
      let scenicHistoryList = wx.getStorageSync('scenicHistory') || [];
      let foodHistoryList = wx.getStorageSync('foodHistory') || [];
  
      this.setData({
        scenicHistoryList: scenicHistoryList,
        foodHistoryList: foodHistoryList,
      });
  
      this.loadHistory(); // 默认加载景点历史
    },
  });
  